﻿/*
* SHARPUPNP
* 
* Written by Marco Minerva, mailto:marco.minerva@gmail.com
* 
* This code is released under the GNU General Public License (GPL) v2.
* A copy of this license is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpUpnp
{
    /// <summary>
    /// Contains detailed information about the response that the UPnP device returned for a specified request.
    /// </summary>
    public class UpnpResponse
    {
        #region Properties

        /// <summary>
        /// Gets the response for the request, if any.
        /// </summary>
        /// <value>The response for the request, if any.</value>
        /// <remarks>If the request causes an error, the <strong>Value</strong> property is set to <strong>null</strong>.</remarks>
        public string Value { get; internal set; }

        /// <summary>
        /// Gets the exception that is been thrown by the request, if any.
        /// </summary>
        /// <value>The exception that is been thrown by the request, if any.</value>
        /// <remarks>If no exceptions are thrown by the request, the <strong>Error</strong> property is set to <strong>null</strong>. If this object isn't <strong>null</strong>, it is possibile to kwnon details about the exception using its <see cref="Code" /> and <see cref="Description"/> properties.</remarks>
        public UpnpException Error { get; internal set; }		

        #endregion

        internal UpnpResponse()
        { }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents the current <see cref="UpnpResponse"/>.
        /// </summary>
        /// <returns>a <see cref="System.String"/> that represents the current <see cref="UpnpResponse"/>.</returns>
        /// <remarks>If the <see cref="UpnpResponse"/> object contains an error, the <strong>ToString</strong> methods returns a string with the format "<em>errorCode: errorDesciption</em>". In any other case, the methods returns the value of the <see cref="Value"/> property.</remarks>
        public override string ToString()
        {
            if (Error != null)
                return string.Format("{0}: {1}", Error.Code, Error.Description);
            return Value;
        }
    }
}
